﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FriendsAccountManagementClassLibrary;
using System.Diagnostics;

namespace TestApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            TransactionDetails td1 = new TransactionDetails()
            {
                TransactionDate = DateTime.Now,
                TransactionDescription = "test desc",
                BalanceAfterTranaction = 10,
                BalanceBeforeTransaction = 20
            };

            Transaction t1 = new Transaction();

            t1.TransactionDetails = new List<TransactionDetails>();
            t1.TransactionDetails.Add(td1);
            t1.TransactionID = "t1";

            Account a1 = new Account();
            a1.Transactions = new Dictionary<string, Transaction>();
            a1.Transactions.Add(t1.TransactionID, t1);
            a1.AccountNumber = "a1";

            User u1 = new User();
            u1.Accounts = new Dictionary<string, Account>();
            u1.Accounts.Add(a1.AccountNumber, a1);
            u1.Email = "aravindsg@live.com";
            u1.FirstName = "Sundar";
            u1.LastName = "Aravind";
            u1.Phone = "006582554430";



            PrintResults(u1);

            if (u1.Accounts.ContainsKey("a1"))
            {
                if (u1.Accounts["a1"].Transactions.ContainsKey("t1"))
                {
                    u1.Accounts["a1"].Transactions["t1"].TransactionDetails.Add(
                        new TransactionDetails
                        {
                            TransactionDate = DateTime.Now,
                            TransactionDescription = "test 2",
                            BalanceAfterTranaction = 13,
                            BalanceBeforeTransaction = 15
                        });
                }
            }

            PrintResults(u1);


            Debug.WriteLine(u1.Accounts.Count);
            Debug.WriteLine(u1.Accounts.Values.Count);
            Debug.WriteLine(u1.Accounts["a1"].Transactions.Count);
            Debug.WriteLine(u1.Accounts["a1"].Transactions["t1"].TransactionDetails.Count);

        }

        private static void PrintResults(User u1)
        {
            foreach (var item in u1.Accounts)
            {
                Debug.WriteLine(item.Key);
                foreach (var te in item.Value.Transactions)
                {
                    Debug.WriteLine(te.Key);

                    foreach (var test in te.Value.TransactionDetails)
                    {
                        Debug.WriteLine(test.TransactionDate);
                        Debug.WriteLine(test.TransactionDescription);
                        Debug.WriteLine(test.BalanceBeforeTransaction);
                        Debug.WriteLine(test.BalanceAfterTranaction);
                    }
                }

            }
        }
    }
}
